from django.db import models
from django.db.models.signals import post_save
from django.contrib.auth.models import User
# Create your models here.

class UserProfile(models.Model):
    user = models.OneToOneField(User)

    # other field
    email = models.EmailField()
    hobby = models.CharField(max_length=32)
    avatar = models.ImageField(upload_to='photo/%Y/%m/%d')


def create_user_profile(sender, instance, created, **kwargs):
    if created:
        profile, created = UserProfile.objects.get_or_create(user=instance)


post_save.connect(create_user_profile, sender=User)




